<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<html:html>
<head>
	<link rel="stylesheet" type="text/css" href="<%= request.getContextPath() %>/css/stkissue2.css" />
	<script type='text/javascript' src='/ittl/dwr/interface/BCProjectService.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/interface/BCItemService.js'></script>	
	<!-- 
  	<script type='text/javascript' src='/ittl/dwr/interface/ItemLocationService.js'></script>
  	 -->  	  	
  	<script type='text/javascript' src='/ittl/dwr/interface/BCAPInvoiceService.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/engine.js'></script>
  	<script type='text/javascript' src='/ittl/dwr/util.js'></script>
  	
<!--  ส่วนที่ 2 -->
<script language="JavaScript">
var	itemCode = "";
function getMaxDocNo(lineNumber, itemOffset) {

	var docDate = "<%=request.getParameter("docDate")%>";
	var myDocDate = new Date("2013-1-1");
	
	var docDate2 = docDate.split("-", 3);

	var yearTh;
	
	if(parseInt(docDate2[0])<2500) {
		yearTh = parseInt(docDate2[0])+543-2500;		
	}else {
		yearTh = parseInt(docDate2[0])-2500;
	}
//	alert('docDate2[1]='+docDate2[1]);
//	alert('parseInt(docDate2[1]='+parseInt(docDate2[1],10));
	var month;
	if(parseInt(docDate2[1],10)<10) {
		month = "0"+parseInt(docDate2[1],10);
	}else {
		month = parseInt(docDate2[1],10);
	}
	
	itemCode	= 	document.getElementById("itemCode"+itemOffset).innerHTML+"-";

//	alert(itemCode+yearTh+month);
	BCAPInvoiceService.getMaxDocNo(itemCode+yearTh+month, loadinfoDocNo);			  
}

//<!--  ส่วนที่ 3 -->
function loadinfoDocNo(maxDocNo){		
	
	//dwr.util.setValue("docNo", maxDocNo.docNo);	
	opener.document.getElementById("docNo").value = itemCode+maxDocNo.docNo;	
	
	if(itemCode=="BCS-") {			
		opener.document.getElementById("billType").value = "0";
		opener.document.getElementById("payAmount").value = opener.document.getElementById("netAmount").value;
		opener.document.getElementById("refNo").value = "ST";
	}else {
		opener.document.getElementById("billType").value = "1";
		opener.document.getElementById("payAmount").value = "0";
		opener.document.getElementById("refNo").value = "";
	}
	
	window.close(); 		
}
</script>
	
</head>

<body ><br />
	<center>

		<div>
		<table border="1">
			<tr>
				<td width="20">ชนิดเอกสาร</td>
				<td width="150">ชื่อ</td>				
			</tr>

			<tr>				
				<td><a href="#" onclick="getMaxDocNo(1,1)" >
						<label id="itemCode1" style="cursor:pointer">BCS</label>
					</a>
				</td>
				<td>ซื้อเงินสด</td>
			</tr>
			<tr>				
				<td><a href="#" onclick="getMaxDocNo(1,2)" >
						<label id="itemCode2" style="cursor:pointer">CRS</label>
					</a>
				</td>
				<td>ซื้อเงินเชื่อ</td>
			</tr>
			<tr>				
				<td><a href="#" onclick="getMaxDocNo(1,3)" >
						<label id="itemCode3" style="cursor:pointer">CMD</label>
					</a>
				</td>
				<td>สีเคมี</td>
			</tr>			
		</table>
		
		</div>
		
		
	</center>
				
</body>

</html:html>